package feeds;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import static feeds.ConnectionUtil.createConnection;

/**
 * Created by sunil.kalva@mkhoj.com.
 * User: sunil.kalva
 * Date: May 11, 2010
 */
public class FeedURL {

    static String filename = "D:\\mkhoj\\codebase\\bashengine_google\\src\\test\\java\\feeds\\urlfeeds.txt";
    static String sql = "insert into feed (url) values (?)";

    public static void main(String[] args) throws SQLException {

        List<String> urlList = getUrlList();
        Connection conn = createConnection();
        PreparedStatement statement = conn.prepareStatement(sql);
        for(String s : urlList) {
            try {
                statement.setString(1, s);
                statement.execute();
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
        conn.close();
    }

    private static List<String> getUrlList() {

        List<String> list = new ArrayList<String>();
        try {

            String line;
            BufferedReader reader = new BufferedReader(new FileReader(filename));
            while(null != (line = reader.readLine())) {
                list.add(line);
            }
            reader.close();
        } catch(Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
